package com.sunday.factory.singletonDemo;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @ClassName LazySingleton
 * @Author JiangHai
 * @Date 2021/9/5 14:33
 **/
public class LazySingleton {

    private static LazySingleton instance;
    private AtomicLong id = new AtomicLong(0);

    private LazySingleton(){
        // 禁止通过反射创建对象
        throw new IllegalArgumentException();
    }

    public static LazySingleton getInstance() {
        if (instance == null) {
            return new LazySingleton();
        }
        return instance;
    }

    public long getId() {
        return id.incrementAndGet();
    }
}
